package com.ssh.dao;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate4.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.ssh.entity.Address_List;
import com.ssh.entity.User;
@Repository
public class UserDaoImpl extends HibernateDaoSupport implements UserDao {
	@Resource(name = "sessionFactory") 
	public void setSuperSessionFactory(SessionFactory sessionFactory){
		super.setSessionFactory(sessionFactory);
	}

	@Override
	public void save(User user) {
		// TODO Auto-generated method stub
		this.getHibernateTemplate().save(user);
	}

	@Override
	public List<User> SelectUser(String username,String password) {
		User user=new User();
		user.setPassword(password);
		user.setUsername(username);
		List<User> list_user=(List<User>) this.getHibernateTemplate().findByExample(user);
		return list_user;
	}

	@Override
	public List<Address_List> selectAll() {
		List<Address_List> list1=(List<Address_List>) this.getHibernateTemplate().find("from Address_List");
		return list1;
	}

	@Override
	public Address_List selectOne(Integer id) {
		Address_List al=this.getHibernateTemplate().get(Address_List.class, id);
		return al;
	}

	@Override
	public void delete(Integer id) {
		Address_List al=this.getHibernateTemplate().get(Address_List.class, id);
		this.getHibernateTemplate().delete(al);
	}

	@Override
	public void update(Address_List al) {
		this.getHibernateTemplate().update(al);
	}

	@Override
	public void save(Address_List al) {
		this.getHibernateTemplate().save(al);
	}

	@Override
	public List<Address_List> select(String str) {
		String hql="from Address_List u where u.name like ? or u.phone like ?";
		String str1="%"+str+"%";
		List<Address_List> al=(List<Address_List>) this.getHibernateTemplate().find(hql,new String[]{str1,str1});
		return al;
	}

	
}
